﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kokomo.PeInspector.ObjectGraphs
{
	class NodeEqualityTemplate<TValue> : NodeTemplate<TValue>
	{
		public object Value { get; private set; }
		public IEqualityComparer<TValue> Comparer { get; private set; }

		public NodeEqualityTemplate(TValue value, IEqualityComparer<TValue> comparer = null)
		{
			this.Value = value;
			this.Comparer = comparer ?? EqualityComparer<TValue>.Default;
		}

		public override bool Inspect(object value)
		{
			if (!(value is TValue)) return false;
			TValue typed = (TValue)value;

			bool matches = object.Equals(this.Value, typed);
			if (matches) this.CapturedValue = typed;

			return matches;
		}
	}
}
